﻿///////////////////////////////////////////////////////
// Library for version 1.0
// langxangvn <langxangvn@gmail.com>
///////////////////////////////////////////////////////
/**
* Modifier name: Đặng Anh Vũ <langxangvn@gmail.com>
* Modifier ID 000
* Date 1/4/2007
* Reason bản đầu tiên
*/

/**
* Modifier name: Đặng Anh Vũ <langxangvn@gmail.com>
* Modifier ID 001
* Date 28/4/2007
* Reason Cac ham va chuc nang coordinate
*/

//---------------------------------------
// show/hide table row - langxangvn VinaCyber JSC 10/2006
//---------------------------------------
function showTableRow(idRow, bVisibility)
{
	if(navigator.appName.indexOf("Microsoft") > -1)
	{
		// neu la IE thi visibility la block
		var canSee = 'block';
	}
	else
	{
		// FF table-row
		var canSee = 'table-row';
	}

	if (document.getElementById && document.createTextNode)
	{
		var tr = document.getElementById(idRow);
		if (tr)
		{
			if(bVisibility == "true")
			{
				// block for IE
				// table-row for FF
				tr.style.display = canSee;
			}
			else if(bVisibility == "false")
			{
				tr.style.display = 'none';
			}
		}
	}
}

function isLegal(szCheck, szInvalid)
{
	// szInvalid cac ky tu dac biet
	for(var i = 0; i < szInvalid.length; i ++)
	{
		// co ky tu dac biet trong chuoi can check
		if(szCheck.indexOf(szInvalid.charAt(i)) >= 0 )
		{
			return false;
		}
    }
	return true;
}

function LTrim(iStr)
{
	if(!iStr)
		return iStr;
	else
		iStr = iStr.toString();
	while (iStr.charCodeAt(0) <= 32)
	{
		iStr = iStr.substr(1);
	}
	return iStr;
}

function RTrim(iStr)
{
	if(!iStr)
		return iStr;
	else
		iStr = iStr.toString();
	while (iStr.charCodeAt(iStr.length - 1) <= 32)
	{
		iStr = iStr.substr(0, iStr.length - 1);
	}
	return iStr;
}

function Trim(iStr)
{
	if(!iStr)
		return iStr;
	else
		iStr = iStr.toString();
	while (iStr.charCodeAt(0) <= 32)
	{
		iStr = iStr.substr(1);
	}

	while (iStr.charCodeAt(iStr.length - 1) <= 32)
	{
		iStr = iStr.substr(0, iStr.length - 1);
	}

	return iStr;
}

function Left(str, n)
{
	if(!str)
		return str;
	else
		str = str.toString();
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0, n);
}

function Right(str, n)
{
	if(!str)
		return str;
	else
		str = str.toString();
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else
    {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

/*
	Author: Matt Kruse <matt@mattkruse.com>
	http://www.mattkruse.com/
*/
function isBlank(val) {
	if(!val) {
		return true;
	}

	for(var i = 0;i < val.length;i ++) {
		if ((val.charAt(i) != ' ')
				&& (val.charAt(i) != "\t")
				&& (val.charAt(i) != "\n")
				&&(val.charAt(i) != "\r")) {
			return false;
		}
	}
	return true;
}

function isInteger(val) {
	if (isBlank(val)) {
		return false;
	}

	for(var i = 0; i < val.length; i++) {
		if(!isDigit(val.charAt(i))) {
			return false;
		}
	}
	return true;
}

function isNumeric(val) {
	return(parseFloat(val, 10) == (val*1));
}

function isArray(obj) {
	return(typeof(obj.length) == "undefined") ? false : true;
}

function isDigit(num) {
	if (num.length > 1) {
		return false;
	}
	var string="1234567890";
	if (string.indexOf(num) != -1) {
		return true;
	}
	return false;
}

function setNullIfBlank(obj) {
	if(isBlank(obj.value)) {
		obj.value = "";
	}
}

function setFieldsToUpperCase() {
	for(var i = 0;i < arguments.length; i++) {
		arguments[i].value = arguments[i].value.toUpperCase();
	}
}
/* end JavascriptToolbox http://www.mattkruse.com/javascript */

function isLeapYear(year) {
	if(!isInteger(year))
		return false;
	return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}

function isDate(datestring) {
	var regex = /\b(0?[1-9]|[12][0-9]|3[01])[-\/.\\/](0?[1-9]|1[012])[-\/.\\/]((19|20)?[0-9]{2})\b/;
	var match = regex.exec(datestring);
	if(!match) {
		return false;
	}
	else {
		var day = parseInt(match[1]);
		var month = parseInt(match[2]);
		var year = parseInt(match[3]);
		if(year < 100)
			year = year + 2000;

		if ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) {
			return false;
		}
 		if (month == 2) {
			if (day > 29 || (day == 29 && !isLeapYear(year))) {
				return false;
			}
 		}
		return true;
	}
}

function isDateBefore(src, dst) {
	var srcDate, dstDate;
	var year, month, day;
	var regex = /\b(0?[1-9]|[12][0-9]|3[01])[-\/.\\/](0?[1-9]|1[012])[-\/.\\/]((19|20)?[0-9]{2})\b/;
	var match = regex.exec(src);
	if(!match) {
		return -1;
	} else {
		day = parseInt(match[1]);
		month = parseInt(match[2]);
		year = parseInt(match[3]);
		if(year < 100)
			year = year + 2000;
		srcDate = new Date(year, month - 1, day);
	}

	match = regex.exec(dst);
	if(!match) {
		return -1;
	} else {
		day = parseInt(match[1]);
		month = parseInt(match[2]);
		year = parseInt(match[3]);
		if(year < 100)
			year = year + 2000;
		dstDate = new Date(year, month - 1, day);
	}

	return (srcDate - dstDate) > 0 ? false : true;
}

function getSelectedOptionLabel(objSelect)
{
	if(objSelect) {
		arOptions = objSelect.getElementsByTagName("option");
		for(var i = 0; i < arOptions.length; i++) {
			if(arOptions[i].selected) {
				return arOptions[i].label;
			}
		}
	}
	return '';
}

function getSelectedOptionInnerHTML(objSelect)
{
	if(objSelect)
	{
		arOptions = objSelect.getElementsByTagName("option");
		for(var i = 0; i < arOptions.length; i++)
		{
			if(arOptions[i].selected)
			{
				return arOptions[i].innerHTML;
			}
		}
	}
	return '';
}

function getEnter(field, event)
{
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13)
	{
		return true;
	}
	else
		return false;
}

function getEscape(field, event)
{
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 27)
	{
		return true;
	}
	else
		return false;
}

function raiseKeyEvent(keyCode, objTarget)
{
	var fireOn = document.getElementById(objTarget);
	// Neu co createEvent
	if(document.createEvent)
	{
		// Neu co KeyEvent (FireFox)
		if(window.KeyEvent)
		{
		  	var evObj = document.createEvent('KeyEvents');
		  	evObj.initKeyEvent('keypress', true, true, window, false, false, false, false, keyCode, 0);
		}
		// Khong ho tro KeyEvent, dung UIEvent thay the
		else
		{
		  	var evObj = document.createEvent('UIEvents');
		  	evObj.initUIEvent('keypress', true, true, window, 1);
		  	evObj.keyCode = keyCode;
		}
		fireOn.dispatchEvent(evObj);
	}
	// Neu co createEventObject (IE dung fireEvent)
	else if(document.createEventObject)
	{
		var evObj = document.createEventObject();
			evObj.ctrlKey = false;
			evObj.altKey = false;
			evObj.shiftKey = false;
			evObj.keyCode = keyCode;
	  	fireOn.fireEvent('onkeypress', evObj);
	}
}

function raiseEnterEvent(objTarget)
{
	raiseKeyEvent(13, objTarget);
}

var glErrorCount = 0;
var glErrorMsg = new Array();
var glHasFocus = false;
glErrorMsg[0] = "---- The following errors occured ----" + String.fromCharCode(10);

function checkField(type, field, message)
{
	var fieldvalue = Trim(field.value);
	var bAllValid = true;
	var bFlagDot  = false;

	// Blank error
	if (type == 'noblank')
	{
		if (fieldvalue == "")
	  	{
		  	glErrorCount ++;
			glErrorMsg[glErrorCount] = message + String.fromCharCode(10);
			if(glHasFocus == false)
			{
				glHasFocus = true;
				field.focus();
			}
  		}
	}
	// Kiem tra dien chi email
	else if(type == 'email')
	{
		if(!isEmail(fieldvalue))
		{
			glErrorCount ++;
			glErrorMsg[glErrorCount] = message + String.fromCharCode(10);
			if(glHasFocus == false)
			{
				glHasFocus = true;
				field.focus();
			}
		}
	}
	else if(type == 'username')
	{
		/* ^(([A-Za-z\d][A-Za-z\d_]+[a-zA-Z\d])|([a-zA-Z\d]+))$ */
		// neu co underscore thi khong nam dau hay cuoi username
		if (!fieldvalue.match(/^(([A-Za-z\d][A-Za-z\d_]+[a-zA-Z\d])|([a-zA-Z\d]+))$/))
		{
			glErrorCount ++;
			glErrorMsg[glErrorCount] = message + String.fromCharCode(10);
			if(glHasFocus == false)
			{
				glHasFocus = true;
				field.focus();
			}
		}
	}
	else if(type == 'captcha')
	{
		/* ^[A-Z0-9]{5}$ */
		if (!fieldvalue.match(/^[a-zA-Z0-9]{5}$/))
		{
			glErrorCount ++;
			glErrorMsg[glErrorCount] = message + String.fromCharCode(10);
			if(glHasFocus == false)
			{
				glHasFocus = true;
				field.focus();
			}
		}
	}
	else if(type == 'mobile')
	{
		/* ^((\(\+?\d{1,3}\))|(\+?\d{1,3}))*[.-\s]?\d{4}[.-\s]?\d+$	*/
		/* part 1: match (code) (+code) +code code voi code tu 1 den 3 so */
		/* co hay khong co phan cach space - hay . */
		/* tiep theo 4 chu so */
		/* co hay khong co phan cach space - hay . */
		if (!fieldvalue.match(/^((\(\+?84\)[\-\.\s]?)|(\+?84[\-\.\s]?)|(0))((9\d{2}[\-\.\s]?\d{6})|(9\d{1}[\-\.\s]?\d{7}))$/))
		{
			glErrorCount ++;
			glErrorMsg[glErrorCount] = message + String.fromCharCode(10);
			if(glHasFocus == false)
			{
				glHasFocus = true;
				field.focus();
			}
		}
	}
	else if(type == 'phone')
	{
		if (!fieldvalue.match(/^((\(\d{2,4}\)[\-\.\s]?)|(\d{2,4}[\-\.\s]?))?(\d{3}[\-\.\s]?\d{3,4})$/))
		{
			glErrorCount ++;
			glErrorMsg[glErrorCount] = message + String.fromCharCode(10);
			if(glHasFocus == false)
			{
				glHasFocus = true;
				field.focus();
			}
		}
	}
	else
	{

	}
}

function isEmail(email)
{
	if(email.match(/^([a-z0-9+_]|\-|\.)+@(([a-z0-9_]|\-)+\.)+[a-z]{2,6}$/))
		return true;
	return false;
}

/*
    Original code from www.yahoo.com

    - Netscape Navigator 4.x (ns4): The most important test - NS4 does
    almost everything differently to the other browsers.

    - Opera 5 (op5): Opera 5 lacks some of the functions that other browsers have.
    These include not being able to change an elements background colour and style class.
    Opera 5 also chokes when sizes and co-ordinates are set using the "px" suffix.

    - Opera 6 (op6): Opera 6 only lacks the ability to change an elements style class.

    - MSIE on the Mac (mac_ie): The problem with MSIE on the Mac is when you try to get
    the top co-ordinate of a table cell element. It incorrectly returns the top co-ordinate
    of the table element, not the table cell. To get round this, you have to base positioning
    on table row elements instead. Konqueror on Linux seems to have the opposite problem which adds to the fun.
*/
function sniffBrowsers() {
    d = document;
    this.agt = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.dom = (d.getElementById) ? 1 : 0; // true for ie6, ns6
    this.ns = (d.layers);
    this.ns4up = (this.ns && this.major >= 4);
    this.ns6 = (this.dom&&navigator.appName == "Netscape");
    this.op = (window.opera ? 1 : 0);
    this.op5 = (navigator.userAgent.indexOf("Opera 5") != -1) || (navigator.userAgent.indexOf("Opera/5") != -1);
    this.op6 = (navigator.userAgent.indexOf("Opera 6") != -1) || (navigator.userAgent.indexOf("Opera/6") != -1);
    this.ie = (d.all);
    this.ie4 = (d.all && !this.dom) ? 1 : 0;
    this.ie4up = (this.ie && this.major >= 4);
    this.ie5 = (d.all && this.dom);
    this.win = ((this.agt.indexOf("win") != -1) || (this.agt.indexOf("16bit") != -1));
    this.mac = (this.agt.indexOf("mac") != -1);
}

var objBrowser = new sniffBrowsers();
/* end determine browser */

function getStyleObject(objectId) {
    if(document.getElementById && document.getElementById(objectId)) {
    	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
    	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
        return getObjNN4(document,objectId);
    } else {
    	return false;
    }
}

function changeObjectVisibility(objectId, newVisibility) {
    var styleObject = getStyleObject(objectId, document);
    if(styleObject) {
    	styleObject.visibility = newVisibility;
    	return true;
    } else {
  	  return false;
    }
}

function findImage(name, doc) {
    var i, img;
    for (i = 0; i < doc.images.length; i++) {
        if (doc.images[i].name == name) {
	        return doc.images[i];
        }
    }
    for (i = 0; i < doc.layers.length; i++) {
        if ((img = findImage(name, doc.layers[i].document)) != null) {
	        img.container = doc.layers[i];
	        return img;
        }
    }
    return null;
}

function getImage(name) {
    if (document.layers) {
        return findImage(name, document);
    }
    return null;
}

function getObjNN4(obj,name)
{
    var x = obj.layers;
    var foundLayer;
    for (var i=0;i<x.length;i++)
    {
        if (x[i].id == name)
 	        foundLayer = x[i];
        else if (x[i].layers.length)
	        var tmp = getObjNN4(x[i],name);
        if (tmp) foundLayer = tmp;
    }
    return foundLayer;
}

function getElementHeight(element) {
    if (objBrowser.ns4) {
        var elem = getObjNN4(document, element);
        return elem.clip.height;
    } else {
        var elem;
        if(document.getElementById) {
	        var elem = document.getElementById(element);
        } else if (document.all){
	        var elem = document.all[element];
        }
        if (objBrowser.op5) {
	        xPos = elem.style.pixelHeight;
        } else {
	        xPos = elem.offsetHeight;
        }
        return xPos;
    }
}

function getElementWidth(element) {
    if (objBrowser.ns4) {
        var elem = getObjNN4(document, element);
        return elem.clip.width;
    } else {
        var elem;
        if(document.getElementById) {
	        var elem = document.getElementById(element);
        } else if (document.all){
	        var elem = document.all[element];
        }
        if (objBrowser.op5) {
	        xPos = elem.style.pixelWidth;
        } else {
	        xPos = elem.offsetWidth;
        }
        return xPos;
    }
}

function getElementLeft(element) {
    if (objBrowser.ns4) {
        var elem = getObjNN4(document, element);
        return elem.pageX;
    } else {
        var elem;
        if(document.getElementById) {
	        var elem = document.getElementById(element);
        } else if (document.all){
	        var elem = document.all[element];
        }
        xPos = elem.offsetLeft;
        tempEl = elem.offsetParent;
        while (tempEl != null) {
	        xPos += tempEl.offsetLeft;
	        tempEl = tempEl.offsetParent;
        }
        return xPos;
    }
}

function getElementTop(element) {
    if (objBrowser.ns4) {
        var elem = getObjNN4(document, element);
        return elem.pageY;
    } else {
        if(document.getElementById) {
	        var elem = document.getElementById(element);
        } else if (document.all) {
	        var elem = document.all[element];
        }
        yPos = elem.offsetTop;
        tempEl = elem.offsetParent;
        while (tempEl != null) {
	        yPos += tempEl.offsetTop;
	        tempEl = tempEl.offsetParent;
        }
        return yPos;
    }
}

function getImageLeft(myImage) {
    var x, obj;
    if (document.layers) {
        var img = getImage(myImage);
        if (img.container != null)
	        return img.container.pageX + img.x;
        else
	        return img.x;
    } else {
        return getElementLeft(myImage);
    }
    return -1;
}

function getImageTop(myImage) {
    var y, obj;
    if (document.layers) {
        var img = getImage(myImage);
        if (img.container != null)
	        return img.container.pageY + img.y;
        else
	        return img.y;
    } else {
        return getElementTop(myImage);
    }
    return -1;
}

function getImageWidth(myImage) {
    var x, obj;
    if (document.layers) {
        var img = getImage(myImage);
        return img.width;
    } else {
        return getElementWidth(myImage);
    }
    return -1;
}

function getImageHeight(myImage) {
    var y, obj;
    if (document.layers) {
        var img = getImage(myImage);
        return img.height;
    } else {
        return getElementHeight(myImage);
    }
    return -1;
}

function moveXY(myObject, x, y) {
    obj = getStyleObject(myObject)
    if (objBrowser.ns4) {
        obj.top = y;
        obj.left = x;
    } else {
        if (objBrowser.op5) {
	        obj.pixelTop = y;
	        obj.pixelLeft = x;
        } else {
	        obj.top = y + 'px';
	        obj.left = x + 'px';
        }
    }
}

function changeClass(element, myClass) {
    var elem;
    if(document.getElementById) {
        var elem = document.getElementById(element);
    } else if (document.all){
        var elem = document.all[element];
    }
    elem.className = myClass;
}

function changeImage(target, source) {
    var imageObj;

    if (objBrowser.ns4) {
        imageObj = getImage(target);
        if (imageObj) imageObj.src = eval(source).src;
    } else {
        imageObj = eval('document.images.' + target);
        if (imageObj) imageObj.src = eval(source).src;
    }
}

function changeBGColour(myObject, colour) {
    if (objBrowser.ns4) {
        var obj = getObjNN4(document, myObject);
        obj.bgColor=colour;
    } else {
        var obj = getStyleObject(myObject);
        if (objBrowser.op5) {
	        obj.background = colour;
        } else {
	        obj.backgroundColor = colour;
        }
    }
}

function getAbsolutePosition(element)
{
    var r = { x: element.offsetLeft, y: element.offsetTop };
    if (element.offsetParent) {
        var tmp = getAbsolutePosition(element.offsetParent);
        r.x += tmp.x;
        r.y += tmp.y;
    }
    return r;
};

/**
* Retrieve the coordinates of the given event relative to the center
* of the widget.
*
* @param event
*  A mouse-related DOM event.
* @param reference
*  A DOM element whose position we want to transform the mouse coordinates to.
* @return
*    A hash containing keys 'x' and 'y'.
*/
function getRelativeCoordinates(event, reference) {
    var x, y;
    event = event || window.event;
    var el = event.target || event.srcElement;
    if (!window.opera && typeof event.offsetX != 'undefined') {
        // Use offset coordinates and find common offsetParent
        var pos = { x: event.offsetX, y: event.offsetY };
        // Send the coordinates upwards through the offsetParent chain.
        var e = el;
        while (e) {
            e.mouseX = pos.x;
            e.mouseY = pos.y;
            pos.x += e.offsetLeft;
            pos.y += e.offsetTop;
            e = e.offsetParent;
        }

        // Look for the coordinates starting from the reference element.
        var e = reference;
        var offset = { x: 0, y: 0 }
        while (e) {
            if (typeof e.mouseX != 'undefined') {
                x = e.mouseX - offset.x;
                y = e.mouseY - offset.y;
                break;
            }
        offset.x += e.offsetLeft;
        offset.y += e.offsetTop;
        e = e.offsetParent;
        }
        // Reset stored coordinates
        e = el;
        while (e) {
            e.mouseX = undefined;
            e.mouseY = undefined;
            e = e.offsetParent;
        }
    }
    else {
        // Use absolute coordinates
        var pos = getAbsolutePosition(reference);
        x = event.pageX  - pos.x;
        y = event.pageY - pos.y;
    }
    // Subtract distance to middle
    return { x: x, y: y };
}

function utf8(wide) {
	var c, s;
  	var enc = "";
  	var i = 0;
  	while(i < wide.length) {
    	c= wide.charCodeAt(i++);
    	// handle UTF-16 surrogates
    	if (c >= 0xDC00 && c < 0xE000) continue;
    	if (c >= 0xD800 && c < 0xDC00) {
      		if (i >= wide.length) continue;
      		s = wide.charCodeAt(i ++);
      		if (s < 0xDC00 || c >= 0xDE00) continue;
      		c= ((c - 0xD800) << 10) + (s - 0xDC00) + 0x10000;
    	}
    	// output value
    	if (c < 0x80) enc += String.fromCharCode(c);
    	else if (c < 0x800) enc += String.fromCharCode(0xC0 + (c >> 6), 0x80 + (c & 0x3F));
    	else if (c < 0x10000) enc += String.fromCharCode(0xE0 + (c >> 12), 0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F));
	    else enc += String.fromCharCode(0xF0 + (c >> 18), 0x80 + (c >> 12 & 0x3F), 0x80 + (c >> 6&0x3F), 0x80 + (c & 0x3F));
  	}
  	return enc;
}

var hexchars = "0123456789ABCDEF";

function toHex(n) {
  	return hexchars.charAt(n >> 4) + hexchars.charAt(n & 0xF);
}


/*
     Example File From "JavaScript and DHTML Cookbook"
     Published by O'Reilly & Associates
     Copyright 2003 Danny Goodman
*/
function getElementStyle(elemID, IEStyleAttr, CSSStyleAttr) {
    var elem = document.getElementById(elemID);
    if(elem != null) {
        if (elem.currentStyle) {
            return elem.currentStyle[IEStyleAttr];
        } else if (window.getComputedStyle) {
            var compStyle = window.getComputedStyle(elem, "");
            return compStyle.getPropertyValue(CSSStyleAttr);
        }
    } else {
        //alert(elemID + " is not an element");
    }
    return "0";
}


function htmlEncode(value) {
    return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\"/g, "&quot;").replace(/\'/g, "&#039;");
}

function htmlDecode(value) {
    return value.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, "\"").replace(/&#039;/g, "'");
}

function appendOptionLast(objSelect, text, value)
{
    var newOpt = document.createElement('option');
    newOpt.text = text;
    newOpt.value = value;

    try {
        objSelect.add(newOpt, null); // standards compliant; doesn't work in IE
    } catch(ex) {
        objSelect.add(newOpt); // IE only
    }
}

// ThaoNguyen
// 123456.789 -> 123,456.789
function toNumericString(obj){
    var str= new String(obj);
    if(str == null || str.length < 1)
        return "";
    var strs = null;
    if(str.indexOf(".", 0) >= 0) {
        strs = str.split(".");
    } else {
        strs = new Array();
        strs[0] = str;
    }
    var result = "";
    var index = strs[0].length;
    var len = strs[0].length;
    do{
        var num = (index >= 3) ? 3 : index;
        index = ((index - 3) > 0) ? (index - 3) : 0;
        result =  strs[0].substr(index, num) + (result.length > 0 ? "," : "") + result;        
    } while(index > 0);
    
    if(strs.length > 1 && strs[1].length > 0) {
        result += "." + strs[1];
    }
    
    return result;
}

function getURLParam( name ) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function getFileExtension(fileName) 
{ 
    if(fileName.length == 0) {
        return ""; 
    }
    var dot = fileName.lastIndexOf("."); 
    if(dot == -1) {
        return ""; 
    }
    var extension = fileName.substr(dot, fileName.length); 
    return extension; 
}

function checkFileType(fileName, allowedExt) 
{ 
    if (!isArray(allowedExt)) {
        return false;
    }
    
    if (!fileName) 
        return true;
        
    var ext = getFileExtension(fileName); 
    
    if( ext == "" ) {
        return false; 
    } else {
        ext = ext.toLowerCase();
        for(var i = 0; i < allowedExt.length; i++) {
            if(ext == allowedExt[i].toLowerCase()) {
                return true;
            }
        }
    }
    return false;
}

function getIEVersionNumber() {
    var ua = navigator.userAgent;
    var MSIEOffset = ua.indexOf("MSIE ");
    
    if (MSIEOffset == -1) {
        return 0;
    } else {
        return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
    }
}